Skip to content

feat: add stats/base/dists/log-logistic/pdf#11203

Open
parthodas23 wants to merge 1 commit intostdlib-js:developfrom
parthodas23:feat/stat-base-dists-log-logistic-pdf
Open

feat: add stats/base/dists/log-logistic/pdf#11203
parthodas23 wants to merge 1 commit intostdlib-js:developfrom
parthodas23:feat/stat-base-dists-log-logistic-pdf

Conversation

@parthodas23
Copy link
Copy Markdown
Contributor

none

Description

What is the purpose of this pull request?

This pull request:

  • feat: add stats/base/dists/log-logistic/pdf

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

{{TODO: add disclosure if applicable}}


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Mar 29, 2026
@stdlib-bot
Copy link
Copy Markdown
Contributor

stdlib-bot commented Mar 29, 2026

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/log-logistic/pdf $\color{green}307/307$
$\color{green}+0.00%$
$\color{green}25/25$
$\color{green}+0.00%$
$\color{green}4/4$
$\color{green}+0.00%$
$\color{green}307/307$
$\color{green}+0.00%$

The above coverage report was generated for the changes in this PR.

@parthodas23 parthodas23 force-pushed the feat/stat-base-dists-log-logistic-pdf branch 3 times, most recently from 5cf562d to 13f4fad Compare March 29, 2026 17:58
@parthodas23 parthodas23 force-pushed the feat/stat-base-dists-log-logistic-pdf branch from 13f4fad to cbec15c Compare March 29, 2026 18:08
@github-actions github-actions bot mentioned this pull request Mar 29, 2026
Comment on lines +19 to +20
import Distributions: pdf, Log-logistic
import JSON
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Julia doesn't have log-logistic or fisk distribution. For that reason upon running this script, module import error takes place. Scipy has fisk distribution, but the parameterization is different. Refer to scipy docs for more info. This pdf function import for log logistic isn't even used in later part of the script.

Comment on lines +43 to +52
function gen( x, alpha, beta, name )
z = Array{Float64}( undef, length(x) );
for i in eachindex(x)
if x[i] < 0.0
z[i] = 0.0;
else
r = x[i] / alpha[i];
z[i] = (beta[i] / alpha[i]) * r^(beta[i] - 1.0) / (1.0 + r^beta[i])^2;
end
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To generate fixtures, generally already implemented library functions are used. For this case use scipy fisk distribution pdf.

Comment on lines +47 to +57
y = pdf( NaN, 1.0, 1.0 );
t.strictEqual( isnan( y ), true, 'returns expected value' );

y = pdf( 0.5, NaN, 1.0 );
t.strictEqual( isnan( y ), true, 'returns expected value' );

y = pdf( 0.5, 1.0, NaN );
t.strictEqual( isnan( y ), true, 'returns expected value' );

y = pdf( NaN, NaN, NaN );
t.strictEqual( isnan( y ), true, 'returns expected value' );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
y = pdf( NaN, 1.0, 1.0 );
t.strictEqual( isnan( y ), true, 'returns expected value' );
y = pdf( 0.5, NaN, 1.0 );
t.strictEqual( isnan( y ), true, 'returns expected value' );
y = pdf( 0.5, 1.0, NaN );
t.strictEqual( isnan( y ), true, 'returns expected value' );
y = pdf( NaN, NaN, NaN );
t.strictEqual( isnan( y ), true, 'returns expected value' );
y = pdf( NaN, 1.0, 1.0 );
t.strictEqual( isnan( y ), true, 'returns expected value' );
y = pdf( 0.5, NaN, 1.0 );
t.strictEqual( isnan( y ), true, 'returns expected value' );
y = pdf( 0.5, 1.0, NaN );
t.strictEqual( isnan( y ), true, 'returns expected value' );
y = pdf( NaN, 1.0, NaN );
t.strictEqual( isnan( y ), true, 'returns expected value' );
y = pdf( NaN, NaN, 1.0 );
t.strictEqual( isnan( y ), true, 'returns expected value' );
y = pdf( 0.5, NaN, NaN );
t.strictEqual( isnan( y ), true, 'returns expected value' );
y = pdf( NaN, NaN, NaN );
t.strictEqual( isnan( y ), true, 'returns expected value' );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer to normal dist pdf tests. All 3 combinations of two NaN occurences should also be tested.

Comment on lines +98 to +102
y = pdf( -1.0, 1.0, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

y = pdf( -10.0, 2.0, 3.0 );
t.strictEqual( y, 0.0, 'returns expected value' );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these test cases test the same thing. My suggestion would be to remove one of them, since both of them check for x<0

Copy link
Copy Markdown
Contributor

@manit2004 manit2004 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments made for test.pdf.js is also applicable for test.native.js and test.factory.js


y = pdf( 1.0, 1.0, NINF );
t.strictEqual( isnan( y ), true, 'returns expected value' );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
y = pdf( 1.0, PINF, NINF );
t.strictEqual( isnan( y ), true, 'returns expected value' );
y = pdf( 1.0, NaN, NINF );
t.strictEqual( isnan( y ), true, 'returns expected value' );
y = pdf( 1.0, NINF, NINF );
t.strictEqual( isnan( y ), true, 'returns expected value' );

Refer to normal pdf tests, combinations of PINF and NaN should also be added with NINF. Import PINF at the top of the file. Same for non positive alpha test cases.

beta = data.beta;
for ( i = 0; i < x.length; i++ ) {
y = pdf( x[ i ], alpha[ i ], beta[ i ] );
if ( expected[ i ] !== null && !( expected[ i ] === 0.0 && y < EPS ) ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( expected[ i ] !== null && !( expected[ i ] === 0.0 && y < EPS ) ) {
if ( expected[ i ] !== null && !( expected[ i ] === 0.0 && y < EPS ) )

!( expected[ i ] === 0.0 && y < EPS this expression is not needed. In your Julia Script x can be equal to 0 thus it's a valid possibilty that expected[ i ] === 0.0 and y can be very small. In normal pdf tests or any other test files we don't use this. Also expected[ i ] !== null is unnecessary, fixtures are already reliably generated.

Comment on lines +132 to +133
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. alpha: '+alpha[ i ]+'. beta: '+beta[ i ]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use @stdlib/assert/is-almost-same-value' instead of delta tolerance tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These images are auto generated, we can remove this file

int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
x[ i ] = random_uniform( 0.0, 20.0 );

the domain for x is [0,inf) so here the lower bound should be zero.

opts = {
'dtype': 'float64'
};
x = uniform( 100, EPS, 20.0, opts );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x = uniform( 100, EPS, 20.0, opts );
x = uniform( 100, 0.0, 20.0, opts );

same comment

opts = {
'dtype': 'float64'
};
x = uniform( 100, EPS, 20.0, opts );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x = uniform( 100, EPS, 20.0, opts );
x = uniform( 100, 0.0, 20.0, opts );

same comment.

bopts = {
'dtype': 'float64'
};
x = uniform( 100, EPS, 20.0, bopts );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x = uniform( 100, EPS, 20.0, bopts );
x = uniform( 100, 0.0, 20.0, bopts );

same comment

beta <= 0.0
) {
return constantFunction( NaN );
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before returning pdf function we can do some micro-optimization by precomputing beta/alpha and (beta -1) for the exponent.

@manit2004
Copy link
Copy Markdown
Contributor

comments made for test.pdf.js is also applicable for test.factory.js and test.native.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review A pull request which needs code review. Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants